package com.hay.pay.support;

import com.alibaba.fastjson.JSONObject;
import com.hay.pay.interceptor.PayInterceptor;
import com.hay.pay.model.param.*;
import com.hay.pay.model.result.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 支付插件
 * @author LiMouRen
 * @date 2024/1/24
 */
public interface PayPlugin {


    /**
     * 支付通知
     * @param result 请求
     * @return 回调结果
     */
    default void payNotify(PayNotifyResult result){
        PayInterceptor payInterceptor = PayContext.getPayInterceptor();
        payInterceptor.payNotify(result);
    }

    /**
     * 退款通知
     * @param result 退款结果
     * @return 回调结果
     */
    default void refundNotify(RefundNotifyResult result){
        PayInterceptor payInterceptor = PayContext.getPayInterceptor();
        payInterceptor.refundNotify(result);
    }

    /**
     * 下单
     * @param placeOrderParam 下单参数
     * @return 下单结果
     */
    PlaceOrderResult placeOrder(PlaceOrderParam placeOrderParam);

    /**
     * 取消订单
     * @param closeOrderParam 取消订单参数
     * @return 下单结果
     */
    void closeOrder(CloseOrderParam closeOrderParam);

    /**
     * 查询下单
     * @param searchOrderParam 查询订单参数
     * @return 下单结果
     */
    PayNotifyResult searchPlaceOrder(SearchPlaceOrderParam searchOrderParam);

    /**
     * 唤起收银台
     * @param arouseCashierParam 参数
     * @return 结果
     */
    JSONObject arouseCashier(ArouseCashierParam arouseCashierParam);

    /**
     * 退款订单
     * @param refundOrderParam 退款参数
     * @return 申请退款结果
     */
    RefundOrderResult refundOrder(RefundOrderParam refundOrderParam);

    /**
     * 查询退款订单
     * @param refundOrderParam 退款参数
     * @return 申请退款结果
     */
    RefundNotifyResult searchRefundOrder(SearchRefundOrderParam refundOrderParam);

    /**
     * 处理支付回调
     * @param request 请求
     * @param response 响应
     * @param merchantCode 商户号
     * @return 回调结果
     */
    HandlePayNotifyResult handlePayNotify(HttpServletRequest request, HttpServletResponse response, String merchantCode);

    /**
     * 处理退款回调
     * @param request 请求
     * @param response 响应
     * @param merchantCode 商户号
     * @return 回调结果
     */
    HandleRefundNotifyResult handleRefundNotify(HttpServletRequest request, HttpServletResponse response,String merchantCode);



}
